package org.endy.leisure.diaTracker.entity.question

import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.endy.leisure.diaTracker.entity.User
import java.util.Date

// 问题实体类
@Entity
@Table(name = "questions")
data class Question(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    @Column(name = "content", nullable = false)
    var content: String,

    @OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
    var images: List<Image>? = null,

    @ManyToOne
    @JoinColumn(name = "user_id")
    var user: User,

    @Column(name = "create_at", nullable = false)
    var createAt: Date = Date(),

    @OneToOne(cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
    var answer: Answer? = null,

    // 确保 answer_id 存在并且被正确注解
    @Column(name = "answer_id", insertable = false, updatable = false)
    val answerId: Long? = null
)
